/***************************************************************************
 *   Copyright 2011 by Pardus Topluluğu                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
 ***************************************************************************/


// Here we avoid loading the header multiple times
#ifndef NAZAR_HEADER
#define NAZAR_HEADER

#include <KConfigDialog>

#include <QTimer>

#include <Plasma/ToolTipContent>
#include <Plasma/ToolTipManager>

#include <Plasma/Applet>
#include <Plasma/Svg>

#include "ui_nazarConfig.h"

class QSizeF;

// Define our plasma Applet
class nazar : public Plasma::Applet
{
    Q_OBJECT
    public:
        // Basic Create/Destroy
        nazar(QObject *parent, const QVariantList &args);
        ~nazar();

        // The paintInterface procedure paints the applet to screen
        void paintInterface(QPainter *painter,
                const QStyleOptionGraphicsItem *option,
                const QRect& contentsRect);
        void init();
        void createConfigurationInterface(KConfigDialog *parent);

        virtual QList<QAction*> contextualActions();

    enum ActionState {   /* What is the applet doing */
        Unset = 0,       /* Not set */
        Idle = 1,        /* The applet has been started but nothing done yet */
        IdleError = 2,   /* The last action went wrong, but we're ready to give it another try */
        IdleSuccess = 4, /* Last action succeeded */
        Sending = 8      /* Sending data to the server, waiting for reply */
    };

    private:
        bool protection_working;
        int number_of_attacks, defated_attacks;

        QString m_image_url;

        QTimer *m_timer;

        Plasma::Svg m_nazarSvg;
        QPixmap m_nazarPixmap;

        void updateScalednazarImage();

        Plasma::ToolTipContent toolTipData;

        Ui::nazarConfig ui;

        void setActionState(ActionState state);

        ActionState m_actionState;

        QList<QAction*> m_actions;
        QAction *m_enableNazarAction;
        QAction *m_disableNazarAction;
        QAction *m_sendNazarAction;

    private slots:
        void resetActionState();

    protected slots:
        void showErrors();
        void slotEnableNazar();
        void slotDisableNazar();
        void slotSendNazar();

        void createMenu();

    protected Q_SLOTS:
        void configurationChanged();

    public slots:
        void configChanged();
        bool is_protecting();

};
 
// This is the command that links your applet to the .desktop file
K_EXPORT_PLASMA_APPLET(nazar, nazar)
#endif
